package umage.figures;

import static org.jhotdraw.draw.AttributeKeys.FONT_BOLD;
import static org.jhotdraw.draw.AttributeKeys.STROKE_COLOR;

import java.io.IOException;

import org.jhotdraw.draw.CreationTool;
import org.jhotdraw.draw.Figure;
import org.jhotdraw.draw.GraphicalCompositeFigure;
import org.jhotdraw.draw.ListFigure;
import org.jhotdraw.draw.RectangleFigure;
import org.jhotdraw.draw.TextFigure;
import org.jhotdraw.draw.VerticalLayouter;
import org.jhotdraw.geom.Insets2DDouble;
import org.jhotdraw.xml.DOMInput;
import org.jhotdraw.xml.DOMOutput;

@FigureInfo(name = "Actor Figure", icon = "ActorFigure.png", toolbar = "Figures", toolbarPriority = 0, tool = CreationTool.class)
public class ActorFigure extends GraphicalCompositeFigure {

	public ActorFigure() {
		super(new RectangleFigure());
		setLayouter(new VerticalLayouter());
		
		fixOutline();
		
		ListFigure ActorCompartment = new ListFigure();

		Insets2DDouble insets = new Insets2DDouble(5, 12, 5, 12);
		LAYOUT_INSETS.set(ActorCompartment, insets);

		ImageFigure actor = new ImageFigure("Actor.png", "/umage/figures/images/");
		ActorCompartment.add(actor);

		TextFigure nameFigure;
		ActorCompartment.add(nameFigure = new TextFigure("Actor"));
		FONT_BOLD.set(nameFigure, true);
		nameFigure.setAttributeEnabled(FONT_BOLD, true);
		add(ActorCompartment);
	}
	
	protected void fixOutline() {
		RectangleFigure presentRect = (RectangleFigure) getPresentationFigure();
		STROKE_COLOR.set(presentRect, null);
		presentRect.setAttributeEnabled(STROKE_COLOR, false);
	}
	
	public ActorFigure clone() {
		ActorFigure that = (ActorFigure) super.clone();
		that.changed();
		return that;
	}

	public void write(DOMOutput out) throws IOException {
		out.writeObject(getPresentationFigure());
		super.write(out);
	}

	@Override
	public void read(DOMInput in) throws IOException {
		removeAllChildren();
		setPresentationFigure((Figure) in.readObject());
		fixOutline();
		super.read(in);
	}

}
